<?php 
/**
 * 支付参数
 */
$url = "pay.baidu.com"; //支付网关联系客服获取
/*************************************************************************************************************/
$paydata = array (
		'mchId' => "600500014", //商户ID，后台提取
		'billNo' => time (), //商户订单号
		'totalAmount' => 5*100, //金额
		'billDesc' => "在线充值", //商品名称
		'way' => "qrcode", //微信扫码模式
		'payment' => 'wechat', //微信支付
		'notifyUrl' => "http://".$_SERVER ['HTTP_HOST']."/notify.php", //回调地址
		'returnUrl' => "http://".$_SERVER ['HTTP_HOST']."/ok.php", //同步跳转
		'attach' => "",
		"accKey" => "" //收款账号
);
$Md5key = "585568557694abf40e541dce26642ea78e3fe999df7aed3496f56203f5b31edd"; //签名密钥，后台提取
$paydata ['sign'] = markSign ( $paydata, $Md5key );
$payUrl = "http://$url/game/unifiedorder"; //请求订单地址
$ret = curl ( $payUrl, json_encode ( $paydata ) );
$data = json_decode ( $ret, true );
if ($data ['code'] == 0) {
	$payCode = $data ['result'] ['payInfo']; //支付二维码
} else {
	exit ( $data ['message'] );
}

/**
 * 请求方法
 */
function curl($url, $post_data) {
	$ch = curl_init ();
	$header = [
			'Content-Type: application/json',
			'Content-Length: ' . strlen ( $post_data )
	];
	curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
	curl_setopt ( $ch, CURLOPT_URL, $url );
	curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
	// 我们在POST数据哦！
	curl_setopt ( $ch, CURLOPT_POST, 1 );
	// 把post的变量加上
	curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
	curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false );
	curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
	
	$output = curl_exec ( $ch );
	curl_close ( $ch );
	return $output;
}

/**
 * 签名方法
 */
function markSign($paydata, $signkey) {
	ksort ( $paydata );
	$str = '';
	foreach ( $paydata as $k => $v ) {
		if ($k != "sign" && $v != "") {
			$str .= $k . "=" . $v . "&";
		}
	}
	return strtoupper ( md5 ( $str . "key=" . $signkey ) );
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta name="apple-mobile-web-app-capable" content="no"/>
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="format-detection" content="telephone=no,email=no"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>扫码支付</title>
    <link href="./css/pay.css" rel="stylesheet" media="screen">
    <link href="./css/paybtn.css" rel="stylesheet" media="screen">
    <link href="./css/toastr.min.css" rel="stylesheet" media="screen">
    <script src="./js/jquery.min.js"></script>
</head>
<body>
<div class="body" id="body">
    <div style="position: relative;display: inline-block;">
    	<img id='show_qrcode' alt="加载中..." src="https://sapi.k780.com/?app=qr.get&data=<?php echo $payCode;?>&level=H&size=7" width="250" height="250" style="display: block;">
    </div>
</div>
<script src="./js/toastr.min.js"></script>
<script>
    function check() {
        $.post("本地查订单地址","请求参数",function (data) {            
            if (data.code == 0){
            	window.location.href = "同步跳转地址";
            } else{
            	setTimeout("check()",1000);
            }
        })
    }
    check();
</script>

</body>
</html>
<script>
    //禁止滚动
    document.body.addEventListener('touchmove', function (e) {e.preventDefault();}, {passive: false});
</script>